clear mata
clear matrix
clear
set more off
set maxvar 10000
global data "C:\Users\taiwo\Downloads\Nigeria Data\New_Analysis061424"
cd "$data"
*2003 has spelling names and codes different from the other years*
use "$data\NGIR4BFL.DTA", clear
*to make the sampling stratification alike*
tab v024
decode v024, gen (v024_1)
replace v024_1="nc" if v024==1
replace v024_1="ne" if v024==2
replace v024_1="nw" if v024==3
replace v024_1="se" if v024==4
replace v024_1="ss" if v024==5
replace v024_1="sw" if v024==6
tab v025
decode v025, gen (v025_1)
tab sstate
decode sstate, gen (sstate_1)
replace sstate_1="zamfara" if sstate_1=="zamfora" 
replace sstate_1="fct abuja" if sstate_1=="abuja (fct)" 
replace sstate_1=lower(sstate_1)
gen v022_1 = v024_1 +" "+ sstate_1+" "+  v025_1
encode v022_1, gen (v022_2)
bro v022_2
save "$data\NGIR4BFL_2003 ammended.dta", replace
use "$data\NGIR7AFL.DTA", clear
append using "$data\NGIR6AFL.DTA"
append using "$data\NGIR53FL.DTA"
*to make the sampling stratification alike*
decode v024, gen (v024_1)
replace v024_1="nc" if v024==1
replace v024_1="ne" if v024==2
replace v024_1="nw" if v024==3
replace v024_1="se" if v024==4
replace v024_1="ss" if v024==5
replace v024_1="sw" if v024==6
decode v025, gen (v025_1)
decode sstate, gen (sstate_1)
replace sstate_1=lower(sstate_1)
gen v022_1 = v024_1 +" "+ sstate_1+" "+  v025_1
encode v022_1, gen (v022_2)
bro v022_2
append using "$data\NGIR4BFL_2003 ammended.dta"
tab v022_2 v007
*recode of household head sex/gender, HH head male(1) female(0)*
*make unique strata values by region/urban-rural (label option automatically labels the results) 
egen strata = group(v024 v025), label 
*check results 
tab strata v007, missing

*Recode missing values to '.'
summ v152
mvdecode v104 v152, mv(98,99)
summ v106 v119 v120 v121 v122 v123 v124 v125 v134 v135 v140 v141 v149 v160 v169a v169b v170 v719 v721 v732 v741 v457 hw57*
*7 not dejure resident, 8 is DK (don't know), and 9 is missing-treat as missing*
mvdecode v106 v119 v120 v121 v122 v123 v124 v125 v134 v135 v140 v141 v149 v160 v169a v169b v170 v719 v721 v732 v741 v457 hw57* , mv(7,8,9)

summ v107 v113 v116 v127 v128 v129 v130 v131 v133 v139 v150 v161 v717 
*98 is DK (don't know or unknown) and 99 is missing-treat as missing*
mvdecode v107 v113 v116 v127 v128 v129 v130 v131 v133 v139 v150 v161 v717 , mv(98,99,97)

summ v115 v131 v456 hw56*
*998 is DK (don't know or unknown) and 999 is missing-treat as missing*
mvdecode v115 v131 v456 hw56*, mv(999,998,997)

summ hw53* v456 v453
*994, 995, 996 is (not present, refused or other) and 999 is missing-treat as missing*
mvdecode hw53* v456 v453, mv(994,995,996,999)
*recode of household head sex/gender, HH head male(1) female(0)*
tab v151, missing
recode v151 (2=0), gen(hheadsex)
label var hheadsex "1=male and 0=female"
gen hheadage=v152
label var hheadage "Household head's age (years)"
gen age=v012
gen sex=0
recode v102 (2=0), gen (urban)
recode v104 (95=1) (0/90=0) (96/97=0), gen (always_residents)
recode v135 (2=0), gen (usual_residents)
gen education_level=v106
gen education=v133
recode v130 (1/2=1)(3/98=0), gen (christian)
recode v130 (3=1)(1/2=0) (4/98=0), gen (muslim)
gen hhnumber=v136
gen wealthscore=v191/100000
gen sstrata=v022_2
gen dhsclust=v001
gen dhsnumber=v002
gen dhsyear=v007
gen employment=v732
gen employer=v719
replace v717=11 if v717==96
gen earn_type=v741
keep hheadsex hheadage age sex urban always_residents usual_residents education_level education christian muslim hhnumber ///
wealthscore sstrata dhsclust dhsnumber dhsyear caseid employment employer earn_type v717 sstate_1 v104

recode education_level (0=1) (1/3=0), gen (no_education)
recode education_level (1=1) (0=0) (2/3=0), gen (primary)
recode education_level (2=1) (0/1=0) (3=0), gen (secondary)
recode education_level (3=1) (0/2=0), gen (higher)
recode v717 (1/11=1), gen(working)
label var working "Employed"
recode v717 (1=1)(2/11=0), gen(profess)
label var profess "Professional"
recode v717 (2=1)(1=0)(3/11=0), gen(clerical)
label var clerical "Clerical"
recode v717 (3=1)(1/2=0)(4/11=0), gen(sales)
label var sales "Sales"
recode v717 (4/5=1)(10=1)(1/3=0)(6/9=0)(11=0), gen(agric)
label var agric "Ag-employed"
recode v717 (7=1)(1/6=0)(8/11=0), gen(services)
label var services "Services"
recode v717 (8=1)(1/7=0)(9/11=0), gen(skilled_manual)
label var skilled_manual "Skilled manual labor"
recode v717 (9=1)(1/8=0)(10/11=0), gen(unskilled_manual)
label var unskilled_manual "Unskilled manual labor"
recode v717 (11=1)(1/10=0), gen(other)
label var other "Employed_other labor"
recode employment (1=1) (2/3=0), gen (all_year)
recode employment (1=0) (2/3=1), gen (seasonal_occ)
recode employer (1=1) (2/3=0), gen (family)
recode employer (1=0) (2=1) (3=0), gen (others)
recode employer (1/2=0) (3=1), gen (self)
save "$data\allyrwomen-var_int.dta", replace
